from django.conf import settings
from django.conf.urls.defaults import *
from django.views.generic.simple import direct_to_template
from django.contrib.auth import views as auth_views
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns("",
    #url(r"^$", auth_views.login, {"template_name": "homepage.html"}, name="home"),
    url(r"^$", "toefl_app.views.show_homepage", name="home"),
    url(r"^admin/", include(admin.site.urls)),
    url(r"^about/", "toefl_app.views.show_about", name="about"),
    url(r"^contact/", "toefl_app.views.show_contact", name="contact"),
    #url(r"^account/", include("pinax.apps.account.urls")),
    #url(r"^profiles/", include("idios.urls")),
    #url(r"^ehlel/", 'toefl_app.views.ehlel', name="ehlel"),
    url(r"^show_medee/" , 'toefl_app.views.show_medee', name="articles"),
    url(r"^articles/(?P<article_id>\d+)", 'toefl_app.views.detail'),
    url(r"^add_article_comment/(\d+)/$", "toefl_app.views.add_article_comment"),
    url(r"^add_file_comment/(\d+)/$", "toefl_app.views.add_file_comment"),
    url(r"^add_university_comment/(\d+)/$", "toefl_app.views.add_university_comment"),
    url(r"^add_institution_comment/(\d+)/$", "toefl_app.views.add_institution_comment"),
    url(r"^polls/(?P<poll_id>\d+)/vote/(?P<choice_id>\d+)$", 'toefl_app.views.vote'),
    #url(r"^polls/(?P<poll_id>\d+)/results/$", 'toefl_app.views.poll_result'),
    url(r"^categories/(?P<category_id>\d+)/$", 'toefl_app.views.show_category_article'),
    url(r"^files/(?P<file_id>\d+)/$", "toefl_app.views.show_file"),
    url(r"^university/(\d+)/$", "toefl_app.views.show_universities", name="universities"),
    url(r"^universities/(?P<university_id>\d+)/$", "toefl_app.views.show_university"),
    url(r"^institutions/(?P<institution_id>\d+)/$", "toefl_app.views.show_institution"),
    url(r"^institution/$", "toefl_app.views.show_institutions", name="institutions"),
    url(r"^exam/", include("exam.urls")),
    url(r"^accounts/", include("registration.urls")),
    url(r"^profile/(?P<user_id>\d+)/$", "toefl_app.views.show_profile", name="profile"),
    url(r"^files/", "toefl_app.views.show_files", name="files"),
    url(r'^ckeditor/', include('ckeditor.urls')),
    url(r"^search/", "toefl_app.views.search", name="search"),
    url(r"save_article/(?P<article_id>\d+)/$", "toefl_app.views.save_article"),
    url(r"save_university/(?P<university_id>\d+)/$", "toefl_app.views.save_university"),
    url(r"save_institution/(?P<institution_id>\d+)/$", "toefl_app.views.save_institution"),
    url(r"delete_article/(?P<article_id>\d+)/$", "toefl_app.views.delete_article"),
    url(r"delete_university/(?P<university_id>\d+)/$", "toefl_app.views.delete_university"),
    url(r"delete_institution/(?P<institution_id>\d+)/$", "toefl_app.views.delete_institution"),
    url(r"edit_profile/$", "toefl_app.views.edit_profile", name="edit_profile"),
    url(r"edit/$", "toefl_app.views.edit", name="edit"),
    url(r"download/(?P<file_id>\d+)/$", "toefl_app.views.download", name="download"),
    url(r"about_toefl/$", "toefl_app.views.about_toefl", name="about_toefl")
)

urlpatterns += patterns('', 
        (r'^site_media/static/(?P<path>.*)$',
        'django.views.static.serve',
        {'document_root': settings.STATIC_ROOT}
    ))

#if settings.SERVE_MEDIA:
#    urlpatterns += patterns("",
#        url(r"", include("staticfiles.urls")),
#    )

    # static files (images, css, javascript, etc.)
urlpatterns += patterns('',
    (r'^site_media/media/(?P<path>.*)$', 
     'django.views.static.serve', 
     {'document_root': settings.MEDIA_ROOT}
))